﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Xml;

using umbraco.BusinessLogic.Actions;
using umbraco.cms.presentation.Trees;
using umbraco.interfaces;

namespace CodeGecko.Modules.Umbraco.AppCodeEditor
{
	public class CodeEditorTree : BaseTree
	{
		public CodeEditorTree(String applicaton) : base(applicaton) { }

		protected override void CreateAllowedActions(ref List<IAction> actions)
		{
			actions.Clear();
			actions.Add(ActionRefresh.Instance);
		}

		protected override void CreateRootNodeActions(ref List<IAction> actions)
		{
			actions.Clear();
			actions.Add(ActionRefresh.Instance);
		}

		protected override void CreateRootNode(ref XmlTreeNode rootNode)
		{
			rootNode.Icon = FolderIcon;
			rootNode.OpenIcon = FolderIconOpen;
			rootNode.NodeID = "init";
			rootNode.NodeType = String.Concat(rootNode.NodeID, this.TreeAlias);
		}

		public override void Render(ref XmlTree tree)
		{
			XmlTreeNode appCode = this.CreateAppCodeTree();
			if (appCode != null)
			{
				tree.Add(appCode);
			}

			XmlTreeNode userControls = this.CreateUserControlsTree();
			if (userControls != null)
			{
				tree.Add(userControls);
			}
		}

		public override void RenderJS(ref StringBuilder Javascript)
		{
			
		}

		protected XmlTreeNode CreateAppCodeTree()
		{
			if ((base.m_id == -1) && !base.IsDialog)
			{
				AppCodeTree appCode = new AppCodeTree(base.m_app);
				return appCode.RootNode;
			}
			return null;
		}

		protected XmlTreeNode CreateUserControlsTree()
		{
			if ((base.m_id == -1) && !base.IsDialog)
			{
				UserControlsTree userControls = new UserControlsTree(base.m_app);
				return userControls.RootNode;
			}
			return null;
		}
	}
}
